package com.mxpio.erp.equipment.controller;

import com.mxpio.erp.common.equipment.entity.EquipmentUpkeepTaskEvaluate;
import com.mxpio.erp.common.equipment.service.EquipmentUpkeepTaskEvaluateService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.List;


@Tag(name = "EquipmentUpkeepTaskEvaluateController}", description = "保养任务评价")
@RestController
@RequestMapping("/erp/equipment/upkeep/task/evaluate/")
public class EquipmentUpkeepTaskEvaluateController {

    @Autowired
    private EquipmentUpkeepTaskEvaluateService equipmentUpkeepTaskTransferService;


    @GetMapping("list")
    @Operation(summary = "保养任务评价列表", description = "获取保养任务评价列表（无分页）", method = "GET")
    public Result<List<EquipmentUpkeepTaskEvaluate>> list(@Parameter(description="查询参数") Criteria criteria) throws UnsupportedEncodingException {
        List<EquipmentUpkeepTaskEvaluate> list = equipmentUpkeepTaskTransferService.list(EquipmentUpkeepTaskEvaluate.class, criteria);
        return Result.OK(list);
    }

    @GetMapping("page")
    @Operation(summary = "保养任务评价列表", description = "获取保养任务评价列表（分页）", method = "GET")
    public Result<Page<EquipmentUpkeepTaskEvaluate>> page(@Parameter(description="查询参数") Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo) throws UnsupportedEncodingException {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<EquipmentUpkeepTaskEvaluate> pageResult = equipmentUpkeepTaskTransferService.listPage(EquipmentUpkeepTaskEvaluate.class, page, criteria);
        return Result.OK(pageResult);
    }

    @GetMapping("list/{id}")
    @Operation(summary = "根据ID获取保养任务评价列表", description = "根据ID获取保养任务评价列表", method = "GET")
    public Result<EquipmentUpkeepTaskEvaluate> getById(@PathVariable(name = "id", required = true) String id) {
        EquipmentUpkeepTaskEvaluate equipmentUpkeepTaskTransfer = equipmentUpkeepTaskTransferService.getById(EquipmentUpkeepTaskEvaluate.class, id);
        return Result.OK(equipmentUpkeepTaskTransfer);
    }
}
